package com.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.visualization.client.AjaxLoader;
import com.google.gwt.visualization.client.visualizations.AreaChart;
import com.google.gwt.visualization.client.visualizations.BarChart;
import com.google.gwt.visualization.client.visualizations.ColumnChart;
import com.google.gwt.visualization.client.visualizations.LineChart;
import com.google.gwt.visualization.client.visualizations.PieChart;
import com.google.gwt.visualization.client.visualizations.Table;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class CNStatsFront implements EntryPoint {

	private static CNStatsFront singleton;
	
	public VerticalPanel plMain;
	public FlexTable ftHeader;
	public DeckPanel plBody;
	
	public PLSearch plSearch;
	public PLCharts plCharts;
	
//	public static String baseURL = "http://localhost:8080/";
	public static String baseURL = "http://cndata4u.appspot.com/";

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
  	singleton = this;
  	
		AjaxLoader.loadVisualizationApi(new VisLoaded(),
				AreaChart.PACKAGE,
				BarChart.PACKAGE,
				ColumnChart.PACKAGE,
				LineChart.PACKAGE,
				PieChart.PACKAGE,
				Table.PACKAGE);	
	}
  
  public static CNStatsFront get() {
  	return singleton;
  }
}

final class VisLoaded implements Runnable {
	public void run() {
		//Continue to init
		CNStatsFront.get().plMain = new VerticalPanel();
//		CNStatsFront.get().ftHeader = new FlexTable();
		
		CNStatsFront.get().plBody = new DeckPanel();
		CNStatsFront.get().plSearch = new PLSearch();
		CNStatsFront.get().plCharts = new PLCharts();
		
  	CNStatsFront.get().plMain.setSize("100%", "100%");
//  	CNStatsFront.get().plMain.add(CNStatsFront.get().ftHeader);
  	CNStatsFront.get().plMain.add(CNStatsFront.get().plBody);

  	CNStatsFront.get().plBody.setSize("100%", "100%");
  	CNStatsFront.get().plBody.setAnimationEnabled(true);
  	  	  	
  	RootPanel.get().add(CNStatsFront.get().plMain);
  	
		Window.addResizeHandler(new ResizeHandler(){
			public void onResize(ResizeEvent event){				
				CNStatsFront.get().plMain.setSize("100%", "100%");
				CNStatsFront.get().plBody.setSize("100%", "100%");
			}
		});						
		CNStatsFront.get().plSearch.show();
	}
}



